package baidu.d20210907.t1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author habitplus
 * @since 2021-09-07 18:57
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String[] ss = bf.readLine().split(" ");
        int n = Integer.parseInt(ss[0]);
        int k = Integer.parseInt(ss[1]);
        int[][] arr = new int[n][n];
        for (int i = 0; i < n; i++) {
            ss = bf.readLine().split(" ");
            for (int j = 0; j < n; j++) {
                arr[i][j] = Integer.parseInt(ss[j]);
            }

        }
        bf.close();

        int[][] ans = solve(arr, k);
        n = n * k;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                sb.append(ans[i][j]).append(" ");
            }
            sb.append("\n");
        }

        System.out.println(sb.toString());
    }

    private static int[][] solve(int[][] m, int k) {
        if (m == null || m.length == 0 || m[0].length == 0 || k < 1) {
            return new int[0][];
        }

        int n = m.length;

        int[][] res = new int[n * k][n * k];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (m[i][j] == 1) {
                    // 当前小矩阵全部赋 1
                    setOne(res, k * i, k * j, k);
                }
            }

        }
        return res;
    }

    private static void setOne(int[][] res, int x0, int y0, int k) {
        for (int i = x0; i < x0 + k; i++) {
            for (int j = y0; j < y0 + k; j++) {
                res[i][j] = 1;
            }
        }
    }
}
